package com.hzit.servlet;

import cn.hutool.core.util.StrUtil;
import com.hzit.entity.Student;
import com.hzit.service.StudentService;
import com.hzit.service.impl.StudentserviceImpl;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@WebServlet("/student")
public class StudentServlet extends HttpServlet {
	private StudentService studentService;
	@Override
	public void init() throws ServletException {
		studentService = new StudentserviceImpl();
	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String cmd = req.getParameter("cmd");
		if(StrUtil.isNotBlank(cmd)){
			if("list".equals(cmd)){
				list(req,resp);
			}
		}

	}
	// 2. 列表学生
	private void list(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		List<Student> students = studentService.findAll();
		req.setAttribute("students",students);
		req.getRequestDispatcher("/WEB-INF/student/list.jsp").forward(req,resp);
	}
}
